#import "YYText.h"
#import "dfhgwhruebvhrheyadmitultimate.h"
#import "dfhgwhruebvhrheyoutwarddelegate.h"
#import "dfhgwhruebvhrheymergefry.h"
#import "dfhgwhruebvhrheywarrantfeasibleViewController.h"
#import "dfhgwhruebvhrheyoccurrenceadditionalViewController.h"
#import "dfhgwhruebvhrheydefinitelyleakViewController.h"
@interface dfhgwhruebvhrheymergefry ()
@property (nonatomic, strong) dfhgwhruebvhrheyadmitultimate *homeModel;
@property (weak, nonatomic) IBOutlet YYLabel *tipsText;
@property (weak, nonatomic) IBOutlet UILabel *statusText;
@property (weak, nonatomic) IBOutlet UIButton *examineBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tipsTextHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *statusTextHeight;
@end
@implementation dfhgwhruebvhrheymergefry {
	void(^_callback)(void);
}
- (void)awakeFromNib {
	[super awakeFromNib];
	[self configureUI];
}
- (void)configureUI {
	self.tipsText.numberOfLines = 0;
    self.tipsText.font = [UIFont regular:15];
    self.tipsText.textAlignment = NSTextAlignmentCenter;
    self.examineBtn.layer.cornerRadius = 12;
    self.examineBtn.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
}
- (void)reViewing {
    if (self.homeModel.refuse_status == 0) {
        self.statusTextHeight.constant = 33;
        self.statusText.text = @"Reviewing!";
        self.statusText.textColor = text_color2.dhgfywegwygeydwlearneddesignate;
        if (self.homeModel.first_loan <= 1) {
            NSString *tips = @"Please wait patiently. The audit result is expected to be given within 12 hours";
            NSRange range = [tips rangeOfString:@"12"];
            NSMutableAttributedString *matt = [[NSMutableAttributedString alloc] initWithString:tips];
            matt.yy_color = text_color4.dhgfywegwygeydwlearneddesignate;
            matt.yy_font = [UIFont regular:15];
            [matt yy_setColor:text_color5.dhgfywegwygeydwlearneddesignate range:range];
            self.tipsTextHeight.constant = 46;
            self.tipsText.attributedText = matt;
            [self.examineBtn setTitle:@"5 star comment for accelerated review" forState:UIControlStateNormal];
        }else {
            self.tipsTextHeight.constant = 23;
            self.tipsText.textColor = text_color4.dhgfywegwygeydwlearneddesignate;
            self.tipsText.text = @"Hold on please, in the request result";
            [self.examineBtn setTitle:@"Refresh" forState:UIControlStateNormal];
        }
    }else {
        self.statusTextHeight.constant = 66;
        self.statusText.textColor = text_color5.dhgfywegwygeydwlearneddesignate;
        self.statusText.text = @"Sorry, you application has not been approved!";
        self.tipsTextHeight.constant = 23;
        self.tipsText.textColor = text_color4.dhgfywegwygeydwlearneddesignate;
        [self.examineBtn setTitle:@"FeedBack" forState:UIControlStateNormal];
        self.tipsText.text = [NSString stringWithFormat:@"You can try again after %d days.", self.homeModel.forbid_days];
    }
}
- (void)rollBack {
    self.statusTextHeight.constant = 33;
    self.statusText.text = @"Application rollback!";
    self.statusText.textColor = text_color5.dhgfywegwygeydwlearneddesignate;
    self.tipsTextHeight.constant = 115;
    self.tipsText.textColor = text_color4.dhgfywegwygeydwlearneddesignate;
    [self.examineBtn setTitle:@"Complete Information" forState:UIControlStateNormal];
    self.tipsText.text = @"Please make sure that the photo you submit is clear and the ID is within the validity period . After submitted you will have the change to get a loan immediately!";
}
- (void)bindData:(dfhgwhruebvhrheyadmitultimate *)model andCallBack:(void(^)(void))callback {
	_callback = callback;
	self.homeModel = model;
	if (model.status == 2) {
		[self reViewing];
	}
	if (model.status == 4 || model.status == 8) {
		[self rollBack];
	}
}
- (IBAction)btnClick:(UIButton *)sender {
	if (self.homeModel.status == 2) {
		if (self.homeModel.refuse_status == 1) {
			dfhgwhruebvhrheyoccurrenceadditionalViewController *feedVC = [[dfhgwhruebvhrheyoccurrenceadditionalViewController alloc] init];
			feedVC.hidesBottomBarWhenPushed = YES;
			[self.controller.navigationController pushViewController:feedVC animated:YES];
		}else {
			if (self.homeModel.first_loan <= 1) {
				NSLog(@"五星好评");
				NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@?action=write-review", APPID]];
				if([[UIApplication sharedApplication] canOpenURL:url]) {
					[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
				}
			}else {
				if (_callback) {
					_callback();
				}
			}
		}
	}
	if (self.homeModel.status == 4) {
		dfhgwhruebvhrheywarrantfeasibleViewController *identity = (dfhgwhruebvhrheywarrantfeasibleViewController *)[UIStoryboard storyboard:@"Home" withidentifier:@"identity"];
		identity.hidesBottomBarWhenPushed = YES;
		identity.isReAuth = true;
		identity.reback_status = self.homeModel.reback_state;
		[self.controller.navigationController pushViewController:identity animated:YES];
	}
	if (self.homeModel.status == 6) {
		if (_callback) {
			_callback();
		}
	}
	if (self.homeModel.status == 8) {
		NSString *identifier = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%@_%@", [dfhgwhruebvhrheyoptionsaving getUserData].phone, dhgfywegwygeydwconnectionencounter]];
		if (identifier.length) {
			dfhgwhruebvhrheychemistcandidateViewController *identifierVC = [UIStoryboard storyboard:@"Home" withidentifier:identifier];
			identifierVC.hidesBottomBarWhenPushed = YES;
			[self.controller.navigationController pushViewController:identifierVC animated:YES];
		}else {
			dfhgwhruebvhrheydefinitelyleakViewController *basicinfo = (dfhgwhruebvhrheydefinitelyleakViewController *)[UIStoryboard storyboard:@"Home" withidentifier:@"basic_info"];
			basicinfo.hidesBottomBarWhenPushed = YES;
			[self.controller.navigationController pushViewController:basicinfo animated:YES];
		}
	}
}
@end
